package com.example.bingobox.data;

import android.content.Context;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.example.bingobox.data.model.Label;
import com.example.bingobox.data.model.TodoBoxData;

public class TodoboxInitializer implements Initializer {
    private final Gson gson;

    public TodoboxInitializer() {
        this.gson = new GsonBuilder().setPrettyPrinting().create();
    }

    @Override
    public void initialize(Context context, File dataDir) {
        File todoboxFile = new File(dataDir, "todobox.json");
        if (!todoboxFile.exists()) {
            try {
                // 创建默认的标签数据
                List<Label> defaultLabels = new ArrayList<>();
                
                // 创建默认的周标签
                Label weekLabel = new Label();
                weekLabel.setStandard("week");
                Label.CoupleData weekLabelData = new Label.CoupleData();
                Map<String, String> weekMap = new HashMap<>();
                weekMap.put("monday", "工作日");
                weekMap.put("tuesday", "工作日");
                weekMap.put("wednesday", "工作日");
                weekMap.put("thursday", "工作日");
                weekMap.put("friday", "工作日");
                weekMap.put("saturday", "陪伴日");
                weekMap.put("sunday", "自由日");
                weekLabelData.setCouple(weekMap);
                weekLabel.setCoupleData(weekLabelData);
                defaultLabels.add(weekLabel);

                // 创建数据结构
                TodoBoxData data = new TodoBoxData();
                data.setTasks(new ArrayList<>());
                data.setTodoBoxes(new ArrayList<>());
                data.setCurrentScene(new ArrayList<>());
                data.setScenes(new ArrayList<>());
                data.setLabels(defaultLabels);
                
                String json = gson.toJson(data);
                try (FileWriter writer = new FileWriter(todoboxFile)) {
                    writer.write(json);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
} 